from openpyxl.reader.excel import load_workbook
from selenium.webdriver.common.by import By

from Base.Base import Base
from configtest import choose_browser

class Test_qd():
    def test_excel(self,choose_browser):
        driver=choose_browser
        driver.maximize_window()
        page=Base(driver)

        wb=load_workbook('')
        sheet=wb['Sheet1']
        headers=[cell.value for cell in sheet[1]]

        for row in sheet.iter_rows(min_row=2,values_only=True):
            data=dict(zip(headers,row))
            action=data['关键字']
            loc=data['操作元素定位']
            val=data['操作值']

            if action == 'get(url)':
                page.get(val)
            elif action=='sleep':
                page.time(int(val))
            elif action=='send_keys':
                page.send_keys((By.XPATH,loc),val)
            elif action=='click_btn':
                page.click((By.XPATH,loc))
            else:
                print(f"未知操作：{action}")
